package com.iot.compont;

import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 这里将管理网关实例信息
 *
 * @author Administrator
 */
@Component
public class GatewayInstance {
    private ConcurrentHashMap<String, ServerNetwork> GatewayInstanceHashMap = new ConcurrentHashMap<>();

    // 使用 put 方法确保插入或更新
    public ServerNetwork putMap(String gatewayId, ServerNetwork netSocket) {
        return GatewayInstanceHashMap.put(gatewayId, netSocket);
    }

    public void deleteMap(String gatewayId) {
        GatewayInstanceHashMap.remove(gatewayId);
    }

    public ServerNetwork getMap(String gatewayId) {
        return GatewayInstanceHashMap.getOrDefault(gatewayId, null);
    }


    public ConcurrentHashMap getAll() {
        return GatewayInstanceHashMap;
    }
}
